package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-05-19 18:29
 */
public class 题库_0026_删除有序数组中的重复项 {

  static
  class Solution {
    public int removeDuplicates(int[] nums) {
      if (nums == null || nums.length < 2) {
        return nums == null ? 0 : nums.length;
      }

      int slow = 0;
      int fast = 1;
      while (fast < nums.length) {
        if (nums[slow] != nums[fast]) {
          nums[slow + 1] = nums[fast];
          ++slow;
        }
        ++fast;
      }

      return slow + 1;
    }
  }

}
